home *** CD-ROM | disk | FTP | other *** search
-
- /*
- File: RoundRectLibrary.c
-
- Contains: graphics libraries - rounded corner gxRectangle routines
-
- Written by: Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 1/9/95 JD First checked in.
- */
-
- #include "GraphicsLibraries.h"
-
- static void RoundRectPath(Fixed *contourData, register const gxRectangle *r, const gxPoint *ovalSize)
- {
- NilParamReturn(contourData);
- NilParamReturn(r);
- NilParamReturn(ovalSize);
- { register Fixed *contourWalker = contourData;
- register Fixed offX = ovalSize->x/2;
- register Fixed offY = ovalSize->y/2;
- register Fixed maxX = (r->right - r->left) / 2;
- register Fixed maxY = (r->bottom - r->top) / 2;
-
- if (offX > maxX)
- offX = maxX;
- if (offY > maxY)
- offY = maxY;
- *contourWalker++ = 12; /* twelve points, all in all */
- *contourWalker++ = 0x49200000; /* one on, one off, one on... times 4 */
-
- *contourWalker++ = r->left; /* 1st pt (top left corner) */
- *contourWalker++ = r->top + offY;
- *contourWalker++ = r->left; /* 2nd pt */
- *contourWalker++ = r->top;
- *contourWalker++ = r->left + offX; /* 3rd pt */
- *contourWalker++ = r->top;
-
- *contourWalker++ = r->right - offX; /* 4th pt (top right corner) */
- *contourWalker++ = r->top;
- *contourWalker++ = r->right; /* 5th pt */
- *contourWalker++ = r->top;
- *contourWalker++ = r->right; /* 6th pt */
- *contourWalker++ = r->top + offY;
-
- *contourWalker++ = r->right; /* 7th pt (bottom right corner) */
- *contourWalker++ = r->bottom - offY;
- *contourWalker++ = r->right; /* 8th pt */
- *contourWalker++ = r->bottom;
- *contourWalker++ = r->right - offX; /* 9th pt */
- *contourWalker++ = r->bottom;
-
- *contourWalker++ = r->left + offX; /* 10th pt (bottom left corner) */
- *contourWalker++ = r->bottom;
- *contourWalker++ = r->left; /* 11th pt */
- *contourWalker++ = r->bottom;
- *contourWalker++ = r->left; /* 12th pt */
- *contourWalker++ = r->bottom - offY;
- }
- }
-
- gxShape NewRoundRect(const gxRectangle *rectData, const gxPoint *ovalSize)
- {
- long newContour[26];
-
- NilParamReturnNil(rectData);
- NilParamReturnNil(ovalSize);
-
- RoundRectPath(newContour, rectData, ovalSize);
- return NewPath((gxPath *) newContour);
- }
-
- void SetRoundRect(gxShape aShape, const gxRectangle *rectData, const gxPoint *ovalSize)
- {
- long newContour[26];
-
- NilShapeReturn(aShape);
- NilParamReturn(rectData);
- NilParamReturn(ovalSize);
-
- RoundRectPath(newContour, rectData, ovalSize);
- SetPath(aShape, 0, (gxPath *) newContour);
- }
-
- void DrawRoundRect(const gxRectangle *bounds, const gxPoint *ovalSize, gxShapeFill fill)
- {
- NilParamReturn(bounds);
- NilParamReturn(ovalSize);
- { register gxShape newShape = NewRoundRect(bounds, ovalSize);
-
- GXSetShapeFill(newShape, fill);
- GXDrawShape(newShape);
- GXDisposeShape(newShape);
- }
- }
-